package com.imay.live.view;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imay.live.R;

/**
 * Created by liangzhenxiong on 2017/04/07 0007.
 */

public class GridTextLinearLayout extends LinearLayout {
    TextView tv_hotname_id0, tv_hotname_id1;

    public GridTextLinearLayout(Context context) {
        super(context);
        init(context);
    }

    public GridTextLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public GridTextLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public GridTextLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    void init(Context context) {
        View view0 = LayoutInflater.from(context).inflate(R.layout.item_discoverylive_text, this, false);
        tv_hotname_id0 = (TextView) view0.findViewById(R.id.tv_hotname_id);
        addView(view0);
        View view1 = LayoutInflater.from(context).inflate(R.layout.item_discoverylive_text, this, false);
        tv_hotname_id1 = (TextView) view1.findViewById(R.id.tv_hotname_id);
        addView(view1);


    }

    public void setText(CharSequence sequence, CharSequence sequence1) {
        tv_hotname_id0.setText(sequence);
        tv_hotname_id1.setText(sequence1);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int childw = (getMeasuredWidth()) >> 1;
        int maxh = 0;

        for (int i = 0; i < getChildCount(); i++) {
            getChildAt(i).measure(MeasureSpec.makeMeasureSpec(childw, MeasureSpec.EXACTLY), heightMeasureSpec);
            maxh = getChildAt(i).getMeasuredHeight();
        }
        setMeasuredDimension(getMeasuredWidth(), maxh);
    }
}
